
package com.carsite.dao.hibernate;

import java.util.List;

import com.carsite.dao.hibernate.BaseDaoHibernate;
import com.carsite.model.OrderNo;
import com.carsite.dao.OrderNoDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class OrderNoDaoHibernate extends BaseDaoHibernate implements OrderNoDao {

    /**
     * @see com.carsite.dao.OrderNoDao#getOrderNos(com.carsite.model.OrderNo)
     */
    public List getOrderNos(final OrderNo orderNo) {
        return getHibernateTemplate().find("from OrderNo");

        /* Remove the line above and uncomment this code block if you want 
           to use Hibernate's Query by Example API.
        if (orderNo == null) {
            return getHibernateTemplate().find("from OrderNo");
        } else {
            // filter on properties set in the orderNo
            HibernateCallback callback = new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException {
                    Example ex = Example.create(orderNo).ignoreCase().enableLike(MatchMode.ANYWHERE);
                    return session.createCriteria(OrderNo.class).add(ex).list();
                }
            };
            return (List) getHibernateTemplate().execute(callback);
        }*/
    }

    /**
     * @see com.carsite.dao.OrderNoDao#getOrderNo(Long id)
     */
    public OrderNo getOrderNo(final Long id) {
        OrderNo orderNo = (OrderNo) getHibernateTemplate().get(OrderNo.class, id);
        if (orderNo == null) {
            log.warn("uh oh, orderNo with id '" + id + "' not found...");
            throw new ObjectRetrievalFailureException(OrderNo.class, id);
        }

        return orderNo;
    }

    /**
     * @see com.carsite.dao.OrderNoDao#saveOrderNo(OrderNo orderNo)
     */    
    public void saveOrderNo(final OrderNo orderNo) {
        getHibernateTemplate().saveOrUpdate(orderNo);
    }

    /**
     * @see com.carsite.dao.OrderNoDao#removeOrderNo(Long id)
     */
    public void removeOrderNo(final Long id) {
        getHibernateTemplate().delete(getOrderNo(id));
    }
}
